package com.twu.biblioteca;


public class BibliotecaApp
{
    private final InputOutput inputOutput;
    private final Library library;


    public BibliotecaApp(InputOutput inputOutput, Library library)
    {
        this.inputOutput = inputOutput;
        this.library = library;
        this.library.setupLibrary();
    }

    public static void main(String[] args)
    {
        BibliotecaApp bibliotecaApp = new BibliotecaApp(new InputOutput(), new Library());
        bibliotecaApp.runApp();
    }

    public void runApp()
    {
        inputOutput.welcomeMessage();
        library.listBooks();
        boolean askedForExit = false;
        while (!askedForExit)
        {
            inputOutput.displayMenu(library.getLoginStatus());
            askedForExit = processInput(inputOutput.getUserInput());
        }
    }

    private boolean processInput(String menuInput)
    {
        if (menuInput.length() > 1)
            return false;
        char switchInput = menuInput.toUpperCase().charAt(0);
        switch (switchInput)
        {
            case 'A':
                library.listBooks();
                return false;
            case 'B':
                library.checkOutBook();
                return false;
            case 'C':
                library.checkInBook();
                return false;
            case 'D':
                library.listMovies();
                return false;
            case 'E':
                library.checkOutMovie();
                return false;
            case 'F':
                library.checkInMovie();
                return false;
            case 'G':
                library.loginUser();
                return false;
            case 'H':
                library.showInfo();
                return false;
            case 'X':
                return true;
        }
        return false;
    }
}
